package com.mingqi.enetconnected.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * @author yaxi
 * @date 2018/9/14
 */
public class InnerRecyclerView extends RecyclerView {

    private static final long M_STANDARD_PRESS_TIME = 2000L;

    public InnerRecyclerView(Context context) {
        super(context);
    }

    public InnerRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public InnerRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private int x;
    private int y;
    private long pressTime = 0;

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                x = (int) ev.getX();
                y = (int) ev.getY();
                pressTime = System.currentTimeMillis();
                return true;

            case MotionEvent.ACTION_MOVE:
                x = (int) ev.getX();
                y = (int) ev.getY();
                pressTime = 0;
                return false;
            case MotionEvent.ACTION_UP:

                if (x == ev.getX() && y ==ev.getY() && pressTime < System.currentTimeMillis() - M_STANDARD_PRESS_TIME){
                    return true;
                }
                break;
            default:
                break;
        }

        return super.dispatchTouchEvent(ev);
    }

}
